home *** CD-ROM | disk | FTP | other *** search
/ MIDICraft's MIDINET CD-ROM / MIDICraft's MIDINET CD-ROM.iso / DOCS / IRCAM / FILEFMT.ZIP / FILEFMT.TXT
Encoding:
Internet Message Format  |  1994-05-17  |  28.6 KB

  1. From LISTSERV@AUVM.BITNET Sun Dec 16 01:18:56 1990
  2. Received: from corton.inria.fr by nadia.ircam.fr, Sun, 16 Dec 90 01:18:22 +0100
  3. Received: from resin.cicb.fr by corton.inria.fr (5.65+/90.0.9)
  4.     via Fnet-EUnet id AA23876; Sun, 16 Dec 90 01:18:31 +0100 (MET)
  5. Message-Id: <9012160018.AA23876@corton.inria.fr>
  6. Received: by FRCICB62.bitnet; 16 Dec 90 01:03:38 +0100:
  7. Received: from AUVM.BITNET by FRMOP11.BITNET (Mailer R2.03B) with BSMTP id
  8.  8643; Sun, 16 Dec 90 01:08:33 GMT
  9. Received: by AUVM (Mailer R2.07) id 2250; Wed, 12 Dec 90 12:37:25 EST
  10. Date:         Wed, 12 Dec 90 12:36:38 EST
  11. From: Revised List Processor (1.6e) <LISTSERV@AUVM.BITNET>
  12. Subject:      File: "FILEFMT MIDISPEC" being sent to you
  13. To: fingerhu@nadia
  14. Status: RO
  15.  
  16. To get your copy of the 1.0 spec, send a $2 check to:
  17.  
  18. International Midi Association
  19. 5316 West 57th Street
  20. Los Angeles, CA 90056
  21. (818)598-0088
  22.  
  23. Make your checks payable to the IMA.  BYW, the 1.0 spec is technically
  24. identical to the .06 spec, but the description has been re-written.
  25. Since the spec has been offically approved, there shouldn't be any
  26. problem with posting this summary of the .06 spec:
  27.  
  28.  
  29. [This document is Dave Oppenheim's current version of the MIDI file
  30. specification, as sent to those who have participated in its
  31. development.  The consensus seems to be to submit this to the MIDI
  32. Manufacturers' Association as version 1.0.  I apologize for any loss of
  33. clarity that might have occurred in the conversion from a Microsoft Word
  34. document to this pure text file.  I have removed some of the discussion
  35. about recent changes to the specification in order to keep the file size
  36. reasonable.--Doug Wyatt]
  37.  
  38. Standard MIDI Files 0.06        March 1, 1988
  39.  
  40.  
  41. 0  Introduction
  42.  
  43. This describes a proposed standard MIDI file format.  MIDI files contain
  44. one or more MIDI streams, with time information for each event.  Song,
  45. sequence, and track structures, tempo and time signature information,
  46. are all supported.  Track names and other descriptive information may be
  47. stored with the MIDI data.  This format supports multiple tracks and
  48. multiple sequences so that if the user of a program which supports
  49. multiple tracks intends to move a file to another one, this format can
  50. allow that to happen.
  51.  
  52. This spec defines the 8-bit binary data stream used in the file.  The
  53. data can be stored in a binary file, nibbleized, 7-bit-ized for
  54. efficient MIDI transmission, converted to Hex ASCII, or translated
  55. symbolically to a printable text file.  This spec addresses what's in
  56. the 8-bit stream.
  57.  
  58.  
  59. 1  Sequences, Tracks, Chunks:  File Block Structure
  60.  
  61. Sequence files are made up of chunks.  Each chunk has a 4-character type
  62. and a 32-bit length, which is the number of bytes in the chunk.  On the
  63. Macintosh, data is passed either in the data fork of a file, or on the
  64. Clipboard.  (The file type on the Macintosh for a file in this format
  65. will be "Midi".)  On any other computer, the data is simply the contents
  66. of the file.  This structure allows future chunk types to be designed
  67. which may easily be ignored if encountered by a program written before
  68. the chunk type is introduced.   Your programs should expect alien chunks
  69. and treat them as if they weren't there.
  70.  
  71. This proposal defines two types of chunks:  a header chunk and a track
  72. chunk.  A header chunk provides a minimal amount of information
  73. pertaining to the entire MIDI file.  A track chunk contains a sequential
  74. stream of MIDI data which may contain information for up to 16 MIDI
  75. channels.  The concepts of multiple tracks, multiple MIDI outputs,
  76. patterns, sequences, and songs may all be implemented using several
  77. track chunks.
  78.  
  79. A MIDI file always starts with a header chunk, and is followed by one or
  80. more track chunks.
  81.  
  82. MThd  <length of header data>
  83. <header data>
  84. MTrk  <length of track data>
  85. <track data>
  86. MTrk  <length of track data>
  87. <track data>
  88.  ...
  89.  
  90. Track Data Format (MTrk chunk type)
  91.  
  92. The MTrk chunk type is where actual song data is stored.  It is simply a
  93. stream of MIDI events (and non-MIDI events), preceded by delta-time
  94. values.
  95.  
  96. Some numbers in MTrk chunks are represented in a form called a variable-
  97. length quantity. These numbers are represented 7 bits per byte, most
  98. significant bits first.  All bytes except the last have bit 7 set, and
  99. the last byte has bit 7 clear.  If the number is between 0 and 127,  it
  100. is thus represented exactly as one byte.
  101.  
  102. Here are some examples of numbers represented as variable-length
  103. quantities:
  104.  
  105.         Number (hex)    Representation (hex)
  106.         00000000        00
  107.         00000040        40
  108.         0000007F        7F
  109.         00000080        81 00
  110.         00002000        C0 00
  111.         00003FFF        FF 7F
  112.         00004000        81 80 00
  113.         00100000        C0 80 00
  114.         001FFFFF        FF FF 7F
  115.         00200000        81 80 80 00
  116.         08000000        C0 80 80 00
  117.         0FFFFFFF        FF FF FF 7F
  118.  
  119.  
  120. The largest number which is allowed is 0FFFFFFF so that the variable-
  121. length representation must fit in 32 bits in a routine to write
  122. variable-length numbers.  Theoretically, larger numbers are possible,
  123. but 2 x 108 96ths of a beat at a fast tempo of 500 beats per minute is
  124. four days, long enough for any delta-time!
  125.  
  126. Here is the syntax of an MTrk chunk:
  127.  
  128. <track data> = <MTrk event>+
  129.  
  130. <MTrk event> = <delta-time> <event>
  131.  
  132. <delta-time> is stored as a variable-length quantity.  It represents the
  133. amount of time before the following event.  If the first event in a
  134. track occurs at the very beginning of a track, or if two events occur
  135. simultaneously, a delta-time of zero is used.  Delta-times are always
  136. present.  (Not storing delta-times of 0 requires at least two bytes for
  137. any other value, and most delta-times aren't zero.)  Delta-time is in
  138. some fraction of a beat (or a second, for recording a track with SMPTE
  139. times), as specified in the header chunk.
  140.  
  141. <event> = <MIDI event> | <sysex event> | <meta-event>
  142.  
  143. <MIDI event> is any MIDI channel message.  Running status is used:
  144. status bytes may be omitted after the first byte.  The first event in a
  145. file must specify status.  Delta-time is not  considered an event
  146. itself:  it is an integral part of the specification.  Notice that
  147. running status occurs across delta-times.
  148.  
  149. <meta-event> specifies non-MIDI information useful to this format or to
  150. sequencers, with this syntax:
  151.  
  152.         FF <type> <length> <bytes>
  153.  
  154. All meta-events begin with FF, then have an event type byte (which is
  155. always less than 128), and then have the length of the data stored as a
  156. variable-length quantity, and then the data itself.  If there is no
  157. data, the length is 0.  As with sysex events, running status is not
  158. allowed.  As with chunks, future meta-events may be designed which may
  159. not be known to existing programs, so programs must properly ignore
  160. meta-events which they do not recognize, and indeed, should expect to
  161. see them.  New for 0.06:  programs must never ignore the length of a
  162. meta-event which they do recognize, and they shouldn't be surprised if
  163. it's bigger than they expected.  If so, they must ignore everything past
  164. what they know about.  However, they must not add anything of their own
  165. to the end of a meta-event.
  166.  
  167. <sysex event> is used to specify a MIDI system exclusive message, or as
  168. an "escape" to specify any arbitrary bytes to be transmitted.
  169. Unfortunately, some synthesizer manufacturers specify that their system
  170. exclusive messages are to be transmitted as little packets.  Each packet
  171. is only part of an entire syntactical system exclusive message, but the
  172. times they are transmitted at are important.  Examples of this are the
  173. bytes sent in a CZ patch dump, or the FB-01's "system exclusive mode" in
  174. which microtonal data can be transmitted.  To be able to handle
  175. situations like these, two forms of  <sysex event> are provided:
  176.  
  177.         F0 <length> <bytes to be transmitted after F0>
  178.         F7 <length> <all bytes to be transmitted>
  179.  
  180. In both cases, <length> is stored as a variable-length quantity.  It is
  181. equal to the number of bytes following it, not including itself or the
  182. message type (F0 or F7), but all the bytes which follow, including any
  183. F7 at the end which is intended to be transmitted.  The first form, with
  184. the F0 code, is used for syntactically complete system exclusive
  185. messages, or the first packet an a series Q that is, messages in which
  186. the F0 should be transmitted.  The second form is used for the remainder
  187. of the packets within a syntactic sysex message, which do not begin with
  188. F0.  Of course, the F7 is not considered part of the system exclusive
  189. message.  Of course, just as in MIDI, running status is not allowed, in
  190. this case because the length is stored as a variable-length quantity
  191. which may or may not start with bit 7 set.
  192.  
  193. (New to 0.06)  A syntactic system exclusive message must always end with
  194. an F7, even if the real-life device didn't send one, so that you know
  195. when you've reached the end of an entire sysex message without looking
  196. ahead to the next event in the MIDI file.  This principle is repeated
  197. and illustrated in the paragraphs below.
  198.  
  199. The vast majority of system exclusive messages will just use the F0
  200. format.  For instance, the transmitted message F0 43 12 00 07 F7 would
  201. be stored in a MIDI file as F0 05 43 12 00 07 F7.  As mentioned above,
  202. it is required to include the F7 at the end so that the reader of the
  203. MIDI file knows that it has read the entire message.
  204.  
  205. For special situations when a single system exclusive message is split
  206. up, with parts of it being transmitted at different times, such as in a
  207. Casio CZ patch transfer, or the FB-01's "system exclusive mode", the F7
  208. form of sysex event is used for each packet except the first.  None of
  209. the packets would end with an F7 except the last one, which must end
  210. with an F7.  There also must not be any transmittable MIDI events in-
  211. between the packets of a multi-packet system exclusive message.  Here is
  212. an example:  suppose the bytes F0 43 12 00 were to be sent, followed by
  213. a 200-tick delay, followed by the bytes  43 12 00 43 12 00, followed by
  214. a 100-tick delay, followed by the bytes  43 12 00 F7, this would be in
  215. the MIDI File:
  216.  
  217.         F0 03 43 12 00
  218.         81 48                                   200-tick delta-time
  219.         F7 06 43 12 00 43 12 00
  220.         64                                      100-tick delta-time
  221.         F7 04 43 12 00 F7
  222.  
  223. The F7 event may also be used as an "escape" to transmit any bytes
  224. whatsoever, including real-time bytes, song pointer, or MIDI Time Code,
  225. which are not permitted normally in this specification.  No effort
  226. should be made to interpret the bytes used in this way.  Since a system
  227. exclusive message is not being transmitted, it is not necessary or
  228. appropriate to end the F7 event with an F7 in this case.
  229.  
  230.  
  231. 2    Header Chunk
  232.  
  233. The header chunk at the beginning of the file specifies some basic
  234. information about the data in the file.  The data section contains three
  235. 16-bit words, stored high byte first (of course).  Here's the syntax of
  236. the complete chunk:
  237.  
  238.         <chunk type> <length> <format> <ntrks> <division>
  239.  
  240. As described above, <chunk type> is the four ASCII characters 'MThd';
  241. <length> is a 32-bit representation of the number 6 (high byte first).
  242. The first word, format, specifies the overall organization of the file.
  243. Only three values of format are specified:
  244.  
  245.         0       the file contains a single multi-channel track
  246.         1       the file contains one or more simultaneous tracks (or MIDI
  247. outputs) of a sequence
  248.         2       the file contains one or more sequentially independent
  249. single-track patterns
  250.  
  251. The next word, ntrks, is the number of track chunks in the file.  The
  252. third word, division,  is the division of a quarter-note represented by
  253. the delta-times in the file.  (If division is negative, it represents
  254. the division of a second represented by the delta-times in the file, so
  255. that the track can represent events occurring in actual time instead of
  256. metrical time.  It is represented in the following way:  the upper byte
  257. is one of the four values -24, -25, -29, or -30, corresponding to the
  258. four standard SMPTE and MIDI time code formats, and represents the
  259. number of frames per second.  The second byte (stored positive) is the
  260. resolution within a frame:  typical values may be 4 (MIDI time code
  261. resolution), 8, 10, 80 (bit resolution), or 100.  This system allows
  262. exact specification of time-code-based tracks, but also allows
  263. millisecond-based tracks by specifying 25 frames/sec and a resolution of
  264. 40 units per frame.)
  265.  
  266. Format 0, that is, one multi-channel track, is the most interchangeable
  267. representation of data.  One application of MIDI files is a simple
  268. single-track player in a program which needs to make synthesizers make
  269. sounds, but which is primarily concerned with something else such as
  270. mixers or sound effect boxes.  It is very desirable to be able to
  271. produce such a format, even if your program is track-based, in order to
  272. work with these simple programs.  On the other hand, perhaps someone
  273. will write a format conversion from format 1 to format 0 which might be
  274. so easy to use in some setting that it would save you the trouble of
  275. putting it into your program.
  276.  
  277. Programs which support several simultaneous tracks should be able to
  278. save and read data in format 1, a vertically one-dimensional form, that
  279. is, as a collection of tracks.  Programs which support several
  280. independent patterns should be able to save and read data in format 2, a
  281. horizontally one-dimensional form.  Providing these minimum capabilities
  282. will ensure maximum interchangeability.
  283.  
  284. MIDI files can express tempo and time signature, and they have been
  285. chosen to do so for transferring tempo maps from one device to another.
  286. For a format 0 file, the tempo will be scattered through the track and
  287. the tempo map reader should ignore the intervening events; for a format
  288. 1 file, the tempo map must (starting in 0.04) be stored as the first
  289. track.  It is polite to a tempo map reader to offer your user the
  290. ability to make a format 0 file with just the tempo, unless you can use
  291. format 1.
  292.  
  293. All MIDI files should specify tempo and time signature.  If they don't,
  294. the time signature is assumed to be 4/4, and the tempo 120 beats per
  295. minute.  In format 0, these meta-events should occur at least at the
  296. beginning of the single multi-channel track.  In format 1, these meta-
  297. events should be contained in the first track.  In format 2, each of the
  298. temporally independent patterns should contain at least initial time
  299. signature and tempo information.
  300.  
  301. We may decide to define other format IDs to support other structures.  A
  302. program reading an unfamiliar format ID should return an error to the
  303. user rather than trying to read further.
  304.  
  305. 3    Meta-Events
  306.  
  307. A few meta-events are defined herein.  It is not required for every
  308. program to support every meta-event.  Meta-events initially defined
  309. include:
  310.  
  311. FF 00 02 ssss   Sequence Number
  312. This optional event, which must occur at the beginning of a track,
  313. before any nonzero delta-times, and before any transmittable MIDI
  314. events, specifies the number of a sequence.  The number in this track
  315. corresponds to the sequence number in the new Cue message discussed at
  316. the summer 1987 MMA meeting.  In a format 2 MIDI file, it is used to
  317. identify each "pattern" so that a "song" sequence using the Cue message
  318. to refer to the patterns.  If the ID numbers are omitted, the sequences'
  319. locations in order in the file are used as defaults.  In a format 0 or 1
  320. MIDI file, which only contain one sequence, this number should be
  321. contained in the first (or only) track.  If transfer of several
  322. multitrack sequences is required, this must be done as a group of format
  323. 1 files, each with a different sequence number.
  324.  
  325. FF 01 len text  Text Event
  326. Any amount of text describing anything.  It is a good idea to put a text
  327. event right at the beginning of a track, with the name of the track, a
  328. description of its intended orchestration, and any other information
  329. which the user wants to put there.  Text events may also occur at other
  330. times in a track, to be used as lyrics, or descriptions of cue points.
  331. The text in this event should be printable ASCII characters for maximum
  332. interchange.  However, other character codes using the high-order bit
  333. may be used for interchange of files between different programs on the
  334. same computer which supports an extended character set.  Programs on a
  335. computer which does not support non-ASCII characters should ignore those
  336. characters.
  337.  
  338. (New for 0.06 ).  Meta event types 01 through 0F are reserved for
  339. various types of text events, each of which meets the specification of
  340. text events(above) but is used for a different purpose:
  341.  
  342. FF 02 len text  Copyright Notice
  343. Contains a copyright notice as printable ASCII text.  The notice should
  344. contain the characters (C), the year of the copyright, and the owner of
  345. the copyright.  If several pieces of music are in the same MIDI file,
  346. all of the copyright notices should be placed together in this event so
  347. that it will be at the beginning of the file.  This event should be the
  348. first event in the first track chunk, at time 0.
  349.  
  350.  
  351. FF 03 len text  Sequence/Track Name
  352. If in a format 0 track, or the first track in a format 1 file, the name
  353. of the sequence.  Otherwise, the name of the track.
  354.  
  355. FF 04 len text  Instrument Name
  356. A description of the type of instrumentation to be used in that track.
  357. May be used with the MIDI Prefix meta-event to specify which MIDI
  358. channel the description applies to, or the channel may be specified as
  359. text in the event itself.
  360.  
  361. FF 05 len text  Lyric
  362. A lyric to be sung.  Generally, each syllable will be a separate lyric
  363. event which begins at the event's time.
  364.  
  365. FF 06 len text  Marker
  366. Normally in a format 0 track, or the first track in a format 1 file.
  367. The name of that point in the sequence, such as a rehearsal letter or
  368. section name ("First Verse", etc.).
  369.  
  370.  
  371. FF 07 len text  Cue Point
  372. A description of something happening on a film or video screen or stage
  373. at that point in the musical score ("Car crashes into house", "curtain
  374. opens", "she slaps his face", etc.)
  375.  
  376. FF 2F 00        End of Track
  377. This event is not optional.  It is included so that an exact ending
  378. point may be specified for the track, so that it has an exact length,
  379. which is necessary for tracks which are looped or concatenated.
  380.  
  381. FF 51 03 tttttt         Set Tempo, in microseconds per MIDI quarter-note
  382. This event indicates a tempo change.  Another way of putting
  383. "microseconds per quarter-note" is "24ths of a microsecond per MIDI
  384. clock".  Representing tempos as time per beat instead of beat per time
  385. allows absolutely exact long-term synchronization with a time-based sync
  386. protocol such as SMPTE time code or MIDI time code.  This amount of
  387. accuracy provided by this tempo resolution allows a four-minute piece at
  388. 120 beats per minute to be accurate within 500 usec at the end of the
  389. piece.  Ideally, these events should only occur where MIDI clocks would
  390. be located Q this convention is intended to guarantee, or at least
  391. increase the likelihood, of compatibility with other synchronization
  392. devices so that a time signature/tempo map stored in this format may
  393. easily be transferred to another device.
  394.  
  395. FF 54 05 hr mn se fr ff SMPTE Offset  (New in 0.06 - SMPTE Format
  396. specification)
  397. This event, if present, designates the SMPTE time at which the track
  398. chunk is supposed to start.  It should be present at the beginning of
  399. the track, that is, before any nonzero delta-times, and before any
  400. transmittable MIDI events.  The hour must be encoded with the SMPTE
  401. format, just as it is in MIDI Time Code.  In a format 1 file, the SMPTE
  402. Offset must be stored with the tempo map, and has no meaning in any of
  403. the other tracks.  The ff field contains fractional frames, in 100ths of
  404. a frame, even in SMPTE-based tracks which specify a different frame
  405. subdivision for delta-times.
  406.  
  407. FF 58 04 nn dd cc bb    Time Signature
  408. The time signature is expressed as four numbers.  nn and dd represent
  409. the numerator and denominator of the time signature as it would be
  410. notated.  The denominator is a negative power of two:  2 represents a
  411. quarter-note, 3 represents an eighth-note, etc.  The cc parameter
  412. expresses the number of MIDI clocks in a metronome click.  The bb
  413. parameter expresses the number of notated 32nd-notes in a MIDI quarter-
  414. note (24 MIDI Clocks).  This was added because there are already
  415. multiple programs which allow the user to specify that what MIDI thinks
  416. of as a quarter-note (24 clocks) is to be notated as, or related to in
  417. terms of, something else.
  418.  
  419. Therefore, the complete event for 6/8 time, where the metronome clicks
  420. every three eighth-notes, but there are 24 clocks per quarter-note, 72
  421. to the bar, would be (in hex):
  422.  
  423.         FF 58 04 06 03 24 08
  424.  
  425. That is, 6/8 time (8 is 2 to the 3rd power, so this is 06 03), 32 MIDI
  426. clocks per dotted-quarter (24 hex!), and eight notated 32nd-notes per
  427. MIDI quarter note.
  428.  
  429. FF 59 02 sf mi  Key Signature
  430.         sf = -7:  7 flats
  431.         sf = -1:  1 flat
  432.         sf = 0:  key of C
  433.         sf = 1:  1 sharp
  434.         sf = 7: 7 sharps
  435.  
  436.         mi = 0:  major key
  437.         mi = 1:  minor key
  438.  
  439. FF 7F len data  Sequencer-Specific Meta-Event
  440.  
  441.         Special requirements for particular sequencers may use this
  442. event type:  the first byte or bytes of data is a manufacturer ID.
  443. However, as this is an interchange format, growth of the spec proper is
  444. preferred to use of this event type.  This type of event may be used by
  445. a sequencer which elects to use this as its only file format;
  446. sequencers with their established feature-specific formats should
  447. probably stick to the standard features when using this format.
  448.  
  449. 4   Program Fragments and Example MIDI Files
  450.  
  451. Here are some of the routines to read and write variable-length numbers
  452. in MIDI Files.  These routines are in C, and use getc and putc, which
  453. read and write single 8-bit characters from/to the files infile and
  454. outfile.
  455.  
  456. WriteVarLen (value)
  457. register long value;
  458. {
  459.         register long buffer;
  460.  
  461.         buffer = value & 0x7f;
  462.         while ((value >>= 7) > 0)
  463.         {
  464.                 buffer <<= 8;
  465.                 buffer |= 0x80;
  466.                 buffer += (value & 0x7f);
  467.         }
  468.  
  469.         while (TRUE)
  470.         {
  471.                 putc(buffer,outfile);
  472.                 if (buffer & 0x80)
  473.                         buffer >>= 8;
  474.                 else
  475.                         break;
  476.         }
  477. }
  478.  
  479. doubleword ReadVarLen ()
  480. {
  481.         register doubleword value;
  482.         register byte c;
  483.  
  484.         if ((value = getc(infile)) & 0x80)
  485.         {
  486.                 value &= 0x7f;
  487.                 do
  488.                 {
  489.                         value = (value << 7) + ((c = getc(infile)) & 0x7f);
  490.                 } while (c & 0x80);
  491.         }
  492.         return (value);
  493. }
  494.  
  495. As an example, MIDI Files for the following excerpt are shown below.
  496. First, a format 0 file is shown, with all information intermingled;
  497. then, a format 1 file is shown with all data separated into four tracks:
  498. one for tempo and time signature, and three for the notes.  A resolution
  499. of 96 "ticks" per quarter note is used.  A time signature of 4/4 and a
  500. tempo of 120, though implied, are explicitly stated.
  501.  
  502.  
  503.  
  504.  
  505. The contents of the MIDI stream represented by this example are broken
  506. down here:
  507.  
  508. Delta Time(decimal)  Event Code (hex)   Other Bytes (decimal)
  509.         Comment
  510.         0       FF 58   04 04 02 24 08  4 bytes: 4/4 time, 24 MIDI
  511. clocks/click,
  512.                                 8 32nd notes/24 MIDI clocks
  513.         0       FF 51   03 500000       3 bytes: 500,000 5sec per quarter-note
  514.         0       C0      5       Ch. 1, Program Change 5
  515.         0       C0      5       Ch. 1, Program Change 5
  516.         0       C1      46      Ch. 2, Program Change 46
  517.         0       C2      70      Ch. 3, Program Change 70
  518.         0       92      48  96  Ch. 3 Note On C2, forte
  519.         0       92      60  96  Ch. 3 Note On C3, forte
  520.         96      91      67  64  Ch. 2 Note On G3, mezzo-forte
  521.         96      90      76  32  Ch. 1 Note On E4, piano
  522.         192     82      48  64  Ch. 3 Note Off C2, standard
  523.         0       82      60  64  Ch. 3 Note Off C3, standard
  524.         0       81      67  64  Ch. 2 Note Off G3, standard
  525.         0       80      76  64  Ch. 1 Note Off E4, standard
  526.         0       FF 2F   00      Track End
  527.  
  528. The entire format 0 MIDI file contents in hex follow.  First, the header
  529. chunk:
  530.  
  531.                 4D 54 68 64     MThd
  532.                 00 00 00 06     chunk length
  533.                 00 00   format 0
  534.                 00 01   one track
  535.                 00 60   96 per quarter-note
  536.  
  537. Then, the track chunk.  Its header, followed by the events (notice that
  538. running status is used in places):
  539.  
  540.                 4D 54 72 6B     MTrk
  541.                 00 00 00 3B     chunk length (59)
  542.  
  543.         Delta-time      Event   Comments
  544.         00      FF 58 04 04 02 18 08    time signature
  545.         00      FF 51 03 07 A1 20       tempo
  546.         00      C0 05
  547.         00      C1 2E
  548.         00      C2 46
  549.         00      92 30 60
  550.         00      3C 60   running status
  551.         60      91 43 40
  552.         60      90 4C 20
  553.         81 40   82 30 40        two-byte delta-time
  554.         00      3C 40   running status
  555.         00      81 43 40
  556.         00      80 4C 40
  557.         00      FF 2F 00        end of track
  558.  
  559. A format 1 representation of the file is slightly different.  Its header
  560. chunk:
  561.  
  562.                 4D 54 68 64     MThd
  563.                 00 00 00 06     chunk length
  564.                 00 01   format 1
  565.                 00 04   four tracks
  566.                 00 60   96 per quarter-note
  567.  
  568. First, the track chunk for the time signature/tempo track.  Its header,
  569. followed by the events:
  570.  
  571.                 4D 54 72 6B     MTrk
  572.                 00 00 00 14     chunk length (20)
  573.  
  574.         Delta-time      Event   Comments
  575.         00      FF 58 04 04 02 18 08    time signature
  576.         00      FF 51 03 07 A1 20       tempo
  577.         83 00   FF 2F 00        end of track
  578.  
  579. Then, the track chunk for the first music track.  The MIDI convention
  580. for note on/off running status is used in this example:
  581.  
  582.                 4D 54 72 6B     MTrk
  583.                 00 00 00 10     chunk length (16)
  584.  
  585.         Delta-time      Event   Comments
  586.         00      C0 05
  587.         81 40   90 4C 20
  588.         81 40   4C 00   Running status: note on, vel = 0
  589.         00      FF 2F 00        end of track
  590.  
  591. Then, the track chunk for the second music track:
  592.  
  593.                 4D 54 72 6B     MTrk
  594.                 00 00 00 0F     chunk length (15)
  595.  
  596.         Delta-time      Event   Comments
  597.         00      C1 2E
  598.         60      91 43 40
  599.         82 20   43 00   running status
  600.         00      FF 2F 00        end of track
  601.  
  602. Then, the track chunk for the third music track:
  603.  
  604.                 4D 54 72 6B     MTrk
  605.                 00 00 00 15     chunk length (21)
  606.  
  607.         Delta-time      Event   Comments
  608.         00      C2 46
  609.         00      92 30 60
  610.         00      3C 60   running status
  611.         83 00   30 00   two-byte delta-time, running status
  612.         00      3C 00   running status
  613.         00      FF 2F 00        end of track
  614.  
  615. 5   MIDI Transmission of MIDI Files
  616.  
  617. Since it is inconvenient to exchange disks between different computers,
  618. and since many computers which will use this format will have a MIDI
  619. interface anyway, MIDI seems like a perfect way to send these files from
  620. one computer to another.  And, while we're going through all the trouble
  621. to make a way of sending MIDI Files, it would be nice if they could send
  622. any files (like sampled sound files, text files, etc.)
  623.  
  624. Goals
  625. The transmission protocol for MIDI files should be reasonably efficient,
  626. should support fast transmission for computers which are capable of it,
  627. and slower transmission for less powerful ones.  It should not be
  628. impossible to convert a MIDI File to or from an arbitrary internal
  629. representation on the fly as it is transmitted, but, as long as it is
  630. not too difficult, it is very desirable to use a generic method so that
  631. any file type could be accommodated.
  632.  
  633. To make the protocol efficient, the MIDI transmission of these files
  634. will take groups of seven 8-bit bytes and transmit them as eight 7-bit
  635. MIDI data bytes.  This is certainly in the spirit of the rest of this
  636. format (keep it small, because it's not that hard to do).  To
  637. accommodate a wide range of transmission speeds, files will be
  638. transmitted in packets with acknowledge -- this allows data to be stored
  639. to disk as it is received.  If the sender does not receive a response
  640. from a reader in a certain amount of time, it can assume an open-loop
  641. situation, and then just continue.
  642.  
  643. The last edition of MIDI Files contained a specialized protocol for
  644. sending just MIDI Files.  To meet a deadline, unfortunately I don't have
  645. time right now to propose a new generalized protocol.  This will be done
  646. within the next couple of months.  I would welcome any proposals anyone
  647. else has, and would direct your attention to the proposal from Ralph
  648. Muha of Kurzweil, available in a recent MMA bulletin, and also directly
  649. from him.
  650.  
  651.  
  652. --
  653. Michael S. Czeiszperger         | "The only good composer is a dead composer"
  654. Systems Analyst                 | Snail: 2015 Neil Avenue         (614)
  655. The Ohio State University       |        Columbus, OH 43210          292-
  656. ARPA:czei@accelerator.eng.ohio-state.edu  PAN:CZEI                     0161
  657. : MAILER UHCCUX  4/07/89
  658. :lee@uhccux          eharnden@auvm        4/07/89 midi-files
  659.  
  660.  
  661.